<template>
  <view class="container">
    <view class="header">
      <view class="back-arrow" @click="onBack" />
      <text class="title">
        批次结算
      </text>
      <view class="collection-text" @click="onCollectionDoc">
        <image src="@/static/images/share.png" class="pyq-icon" />
        <text>分享</text>
      </view>
    </view>

    <!-- 下面的信息 -->
    <view class="main-container">
      <view class="goods_box" v-for="i in filteredProducts">
        <view class="thegoodsname">
          <view class="font-title">{{ i.name }}</view>
          <view class="font-number">{{ i.number }}</view>
        </view>
        <!-- 下面的时间 -->
        <view class="goods_time">
          {{ i.updatedAt }}&nbsp;&nbsp;{{i.username}}
        </view>
        <!-- 右边的东西 -->
        <view class="right_box" :style="getStatusStyle(i.status)">
          {{ i.status }}
        </view>
        <!-- 右边下面 -->
        <view class="right_box_bottom">
          <img style="color: rgba(154, 156, 161, 1);width: 30rpx;height: 30rpx;margin-top: 16rpx;"
            src="@/static/images/order/add.png" alt="" />
          <view class="right_zi"
            style="color: rgba(67, 207, 124, 1);font-size: 30rpx;font-weight: 500;margin-left: 6rpx;">
            添加货品
          </view>
        </view>
      </view>
      <!-- 123123123123 -->
      <view class="info_goods">
        <div class="info_left">
          库存信息
        </div>
        <img src="@/static/images/filter.png"
          style="width: 28rpx;height: 28rpx;line-height: 28rpx;margin-right: 30rpx;margin-top: 28rpx;" alt="" />
      </view>
      <!-- 下面的 -->
      <view class="titleofname">
        <view class="table-header">
          <view class="table-cell changeit">货品</view>
          <view class="table-cell changeit">入库量</view>
          <view class="table-cell changeit">销量</view>
          <view class="table-cell changeit">库存</view>
          <view class="table-cell changeit">操作</view>
        </view>
        <view class="table-row" v-for="(s,index) in goodsinfo" :key="s.index">
          <view class="table-cell g_more">
            <view class="num_goods">{{index+1}}.</view>
            <view class="num_goods_info">
              <view class="g_name" style="color: rgba(0, 0, 0, 1);font-weight: 600;">{{s.name}}</view>
              <view class="g_care" v-if="s.care===1" style="color: rgba(67, 207, 124, 1);
        border: 1rpx solid rgba(67, 207, 124, 1);">{{s.info}}</view>
              <view class="g_care" v-if="s.care===2"
                style="color: rgba(255, 141, 26, 1);border: 1rpx solid rgba(255, 141, 26, 1);">{{s.info}}</view>
            </view>
          </view>
          <view class="table-cell  changeit" style="color: rgba(0, 0, 0, 1);font-weight: 600;">{{s.get}}件</view>
          <view class="table-cell  changeit" style="color: rgba(0, 0, 0, 1);font-weight: 600;">{{s.sale}}件</view>
          <view class="table-cell  changeit" style="color: rgba(0, 0, 0, 1);font-weight: 600;">{{s.have}}件</view>
          <view class="table-cell  changeit">
            <img src="@/static/images/sandian.png" alt=""
              style="color: rgba(154, 156, 161, 1);width: 11rpx;height: 44rpx;margin-top: 4rpx;margin-left: 13rpx;" />
          </view>
        </view>
      </view>
      <!-- 下面 -->
      <view class="titleofnames">
        <view class="table-row">
          <view class="table-cell g_more"
            style="justify-content: center;align-items: center;padding-bottom: 4rpx;font-weight: 700;">
            合计
          </view>
          <view class="table-cell  changeit">
            <view class="num_goods_info">
              <view class="g_name" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">123件</view>
              <view class="g_cares" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">99999</view>
            </view>
          </view>
          <view class="table-cell  changeit">
            <view class="num_goods_info">
              <view class="g_name" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">123件</view>
              <view class="g_cares" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">99999</view>
            </view>
          </view>
          <view class="table-cell  changeit">
            <view class="num_goods_info">
              <view class="g_name" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">123件</view>
              <view class="g_cares" style="font-size: 30rpx;color: rgba(0, 0, 0, 1);font-weight: 600;">99999</view>
            </view>
          </view>
          <view class="table-cell  changeit">
            &nbsp;
          </view>
        </view>
      </view>
    </view>
    <!-- 底部 -->
  </view>
  <view style="position: sticky;bottom: 0;width: 750rpx; height: 171rpx;border-top: 1rpx solid #cfcfcf;display: flex;">
    <view
      style="width: 266rpx;height: 112rpx;border: 1rpx solid rgba(255, 87, 51, 1);margin: 17rpx 0 0 74rpx;border-radius: 8rpx;
      color: rgba(255, 87, 51, 1);font-size: 36rpx; font-weight: 400;box-sizing: border-box;padding: 26rpx 10rpx 0 60rpx;">
      批次售完
    </view>
    <view style="width: 266rpx;height: 112rpx;font-size: 36rpx; font-weight: 400;box-sizing: border-box;padding: 26rpx 10rpx 0 60rpx;
    background: rgba(128, 128, 128, 1);color:rgba(255, 255, 255, 1);margin: 17rpx 0 0 74rpx;border-radius: 8rpx;">
      库存操作
    </view>
  </view>
</template>

<script setup>
  import {
    ref
  } from 'vue';

  function onBack() {
    uni.navigateBack();
  }
  const keyword = ref('');

  function onSearch() {
    console.log('搜索:', keyword.value);
  }

  function toggleFilter() {
    console.log('切换筛选');
  }

  function onCollectionDoc() {
    console.log('催收文案');
  }
  // 按钮
  const activeTab = ref(0)

  function changeTab(tabIndex) {
    activeTab.value = tabIndex
  }
  const filteredProducts = computed(() => {
    switch (activeTab.value) {
      case 0:
        return products.value.filter(item => item.category === '用户');
      case 1:
        return products.value.filter(item => item.category === '货物');
      default:
        return [];
    }
  });

  // 假数据
  const products = ref([{
    number: '005',
    name: '张三',
    status: '在售',
    sid: 0,
    category: '用户',
    updatedAt: '2024-12-13 09:39',
    username: '肖士举'
  }]);
  const goodsinfo = ref([{
      name: '白菜',
      info: '1件=10公斤',
      care: 1,
      get: 163,
      sale: 13,
      have: 93
    },
    {
      name: '辣椒',
      info: '无定装计件售',
      care: 2,
      get: 163,
      sale: 13,
      have: 93
    }
  ])


  // 颜色
  const getStatusStyle = (status) => {
    if (status === '在售') {
      return {
        backgroundColor: 'rgba(209, 255, 227, 1)'
      };
    } else if (status === '售完') {
      return {
        backgroundColor: 'rgba(250, 207, 165, 1)'
      };
    } else if (status === '结完') {
      return {
        backgroundColor: 'rgba(228, 218, 250, 1.0)'
      };
    } else {
      return {
        backgroundColor: 'rgba(180, 225, 255, 1.0)'
      };
    }
  };
</script>

<style scoped lang="scss">
  .container {
    display: flex;
    flex-direction: column;
    background-color: #f8f8f8;
    min-height: 100vh;
  }

  .header {
    position: relative;
    display: flex;
    align-items: center;
    height: 88rpx;
    padding: 0 20rpx;
    background-color: #ffffff;
    border-bottom: 1rpx solid #f0f0f0;
  }

  .back-arrow {
    position: absolute;
    left: 20rpx;
    width: 30rpx;
    height: 30rpx;
    background: url("@/static/images/order/back.png") no-repeat center;
    background-size: contain;
  }

  .title {
    font-size: 36rpx;
    color: #333;
    font-weight: bold;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  .search-bar {
    display: flex;
    align-items: center;
    height: 80rpx;
    padding: 0 20rpx;
    background-color: #ffffff;
    gap: 10%;
  }

  .search-input {
    flex: 1;
    font-size: 25rpx;
    color: #333;
    font-family: sans-serif;
    border-radius: 20px;
    padding: 10rpx 10rpx 10rpx 60rpx;
    background: rgba(245, 247, 250, 1);
    border: 1px solid rgba(229, 229, 229, 1);
    box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.25);
  }

  .search-icon {
    position: absolute;
    object-fit: cover;
    left: 28rpx;
    width: 30rpx;
    padding: 10rpx;
    height: 30rpx;
  }

  .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .filter {
    display: flex;
    width: 100rpx;
    height: 40rpx;
    font-weight: 500;
    font-size: 32rpx;
  }

  .filter span {
    color: #333;
    margin-left: 4rpx;
    line-height: 40rpx;
  }

  .filter-icon {
    width: 32rpx;
    height: 40rpx;

  }

  /* 按钮 */
  .tabs {
    display: flex;
    justify-content: space-between;
    margin-top: 20rpx;
    border-bottom: 1rpx solid #f5f5f5;
    border: 1rpx solid rgba(67, 207, 124, 1);
    padding: 6rpx;
    background-color: #fff;
  }

  .tab {
    font-size: 32rpx;
    color: #808080;
    padding: 20rpx;
    flex: 1;
    text-align: center;
    border-radius: 5rpx;
    transition: all 0.3s ease;
  }

  .tab.active {
    color: #fff;
    border-radius: 16rpx;
    background-color: rgba(67, 207, 124, 1);
    font-weight: bold;
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25);
  }

  /* 批次信息 */
  .summary {
    padding: 20rpx 40rpx;
    background-color: #ffffff;
  }

  .owe-count {
    font-size: 32rpx;
    color: rgba(128, 128, 128, 1);
    font-weight: 400;
  }

  .owe-count-num {
    color: #FF8D1A;
  }

  /* huowu */
  .goods_box {
    width: 750rpx;
    height: 194rpx;
    margin-top: 20rpx;
    margin-bottom: 4rpx;
    box-shadow: 0 0 5rpx 0 rgba(206, 206, 206, 0.8);
    border: 1rpx solid #efefef;
    background: rgba(128, 128, 128, 1);
    position: relative;

    .right_box {
      position: absolute;
      top: 0;
      right: 36rpx;
      width: 60rpx;
      // border: 1px solid red;
      background: #43cf7c;
      border-radius: 0 0 16rpx 16rpx;
      color: rgba(0, 0, 0, 1);
      padding: 6rpx 9rpx;
    }

    .right_box_bottom {
      position: absolute;
      border-radius: 12rpx;
      background: rgba(255, 255, 255, 1);
      width: 178rpx;
      height: 60rpx;
      line-height: 60rpx;
      justify-content: center;
      display: flex;
      right: 36rpx;
      bottom: 62rpx;
    }

  }

  .thegoodsname {
    margin-top: 44rpx;
    margin-left: 30rpx;
    width: 200rpx;
    height: 60rpx;
    line-height: 60rpx;
    // border: 1px solid red;
    display: flex;
    justify-content: space-between;

    .font-title {
      font-size: 36rpx;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
    }

    .font-number {
      width: 107rpx;
      height: 41rpx;
      line-height: 41rpx;
      background: rgba(166, 166, 166, 1);
      border-radius: 7rpx;
      color: #ffffff;
      text-align: center;
      margin-top: 8rpx;
      margin-left: 3rpx;
    }
  }

  .goods_time {
    color: rgba(166, 166, 166, 1);
    font-size: 30rpx;
    margin-top: 7rpx;
    margin-left: 30rpx;
  }

  .collection-text {
    position: absolute;
    right: 20rpx;
    padding: 10rpx 16rpx;
    border-radius: 6rpx;
    font-size: 30rpx;
    font-weight: 400;
    color: #ffffff;
    background: rgba(67, 207, 124, 1);
    display: flex;
    align-items: center;
  }

  .pyq-icon {
    width: 32rpx;
    height: 32rpx;
    margin-right: 4rpx;
  }

  // 中间的
  .info_goods {
    width: 750rpx;
    height: 90rpx;
    line-height: 90rpx;
    margin-top: 3rpx;
    border-radius: 10rpx 10rpx 0 0;
    // border: 1rpx solid red;
    display: flex;
    justify-content: space-between;

    .info_left {
      font-size: 32rpx;
      margin-left: 30rpx;
      color: rgba(0, 0, 0, 1);
    }
  }

  // 下面的
  .titleofname {
    width: 750rpx;
    // height: 66rpx;
    // line-height: 66rpx;
    display: flex;
    border: 1rpx solid #efefef;
    flex-direction: column;
    background: rgba(245, 245, 245, 1);
    color: rgba(128, 128, 128, 1);
  }

  .titleofnames {
    width: 750rpx;
    // height: 66rpx;
    // line-height: 66rpx;
    display: flex;
    border: 1rpx solid #efefef;
    flex-direction: column;
    font-size: 36rpx;
    // font-weight: 700;
    color: rgba(0, 0, 0, 1);
  }

  .table-header {
    display: flex;
    background-color: #f2f2f2;
    font-weight: bold;
    text-align: center;
    align-items: center;
    font-size: 30rpx;
    font-weight: 400;
  }

  .table-row {
    display: flex;
    border-bottom: 1px solid #ddd;
  }

  .table-cell {
    flex: 1;
    padding: 10rpx 10rpx 0 10rpx;
    height: 101rpx;
    // justify-items: center;
    align-content: center;
    text-align: center;
    display: flex;

    .num_goods {
      font-size: 36rpx;
      font-weight: 500;
      margin-top: 9rpx;
      color: rgba(0, 0, 0, 1);
    }

    .num_goods_info {
      width: 92rpx;
      height: 90rpx;

      // border: 1px solid red;
      .g_name {
        width: 91rpx;
        height: 42rpx;
        line-height: 42rpx;
        font-size: 32rpx;
        color: rgba(0, 0, 0, 1);
        margin-top: 6rpx;
        margin-left: 6rpx;
      }


      .g_care {
        width: 91rpx;
        height: 22rpx;
        line-height: 22rpx;
        font-size: 14rpx;
        border-radius: 7rpx;
        // color: rgba(67, 207, 124, 1);
        // border: 1rpx solid rgba(67, 207, 124, 1);
        padding: 3rpx 4rpx;
        margin: 4rpx 1rpx 0 4rpx;
      }

      .g_cares {
        width: 91rpx;
        height: 22rpx;
        line-height: 22rpx;
        font-size: 28rpx;
        margin: 4rpx 1rpx 0 4rpx;
      }
    }
  }

  .g_more {
    border-right: 1rpx solid #ddd;
    // padding: 0 27rpx 0 0;
    padding-right: 27rpx;
    // box-shadow: 0 2rpx 0 0 #808080;
  }

  .nameofit {
    margin-left: 35rpx;
  }

  .changeit {
    align-items: center;
    justify-content: center;
  }

  .thisof {
    // margin-top: 10rpx;
  }
</style>
